import service from "../utils/request";

/**
 * 根据查询条件获取宝可梦列表
 * @param {Object} params 查询参数
 * @param {string} params.query - 搜索关键词
 * @param {string} params.type1 - 第一属性
 * @param {string} params.type2 - 第二属性
 * @param {string} params.category - 分类
 * @param {number} params.beginNum - 开始编号
 * @param {number} params.endNum - 结束编号
 * @returns {Promise} 宝可梦列表数据
 */
export function getPokemonList(params = {}) {
  return service.get("/pokemon/query", { params });
}

/**
 * 根据VO条件获取宝可梦列表
 * @param {Object} vo 查询VO对象
 * @param {string} vo.query - 搜索关键词
 * @param {string} vo.type1 - 第一属性
 * @param {string} vo.type2 - 第二属性
 * @param {string} vo.category - 分类
 * @param {number} vo.beginNum - 开始编号
 * @param {number} vo.endNum - 结束编号
 * @returns {Promise} 宝可梦列表数据
 */
export function getPokemonListByVO(vo = {}) {
  return service.get("/pokemon/vo", { params: vo });
}

/**
 * 根据查询条件搜索宝可梦
 * @param {string} query 搜索关键词
 * @returns {Promise} 搜索结果
 */
export function searchPokemon(query) {
  return service.get("/pokemon/query", {
    params: { query }
  });
}

/**
 * 根据属性搜索宝可梦
 * @param {string} type1 第一属性
 * @param {string} type2 第二属性（可选）
 * @returns {Promise} 搜索结果
 */
export function getPokemonByType(type1, type2 = null) {
  const params = { type1 };
  if (type2) {
    params.type2 = type2;
  }
  return service.get("/pokemon/query", { params });
}

/**
 * 根据分类搜索宝可梦
 * @param {string} category 宝可梦分类
 * @returns {Promise} 搜索结果
 */
export function getPokemonByCategory(category) {
  return service.get("/pokemon/query", {
    params: { category }
  });
}

/**
 * 根据编号范围搜索宝可梦
 * @param {number} beginNum 开始编号
 * @param {number} endNum 结束编号
 * @returns {Promise} 搜索结果
 */
export function getPokemonByNumberRange(beginNum, endNum) {
  return service.get("/pokemon/query", {
    params: { beginNum, endNum }
  });
}

/**
 * 获取所有宝可梦列表（无参数）
 * @returns {Promise} 所有宝可梦列表数据
 */
export function getAllPokemon() {
  return service.get("/pokemon/list");
}

/**
 * 获取第一世代宝可梦（1-151号）
 * @returns {Promise} 第一世代宝可梦数据
 */
export function getGen1Pokemon() {
  return service.get("/pokemon/gen1");
}

/**
 * 获取用于进化选择器的宝可梦简化列表
 * 只返回id、名称、编号、图片等基本信息，用于下拉选择器
 * @returns {Promise} 宝可梦选择器列表数据
 */
export function getPokemonSelectorList() {
  return service.get("/pokemon/selector-list");
}

/**
 * 获取模拟宝可梦数据（用于后端API不可用时的备用方案）
 * @returns {Promise} 模拟宝可梦列表数据
 */
export function getMockPokemonList() {
  // 当后端不可用时的备用数据
  return Promise.resolve({
    flag: true,
    data: [
      {
        id: 1,
        number: "001",
        pokemonName: "妙蛙种子",
        imageUrl: "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/1.png",
        types: [{ id: 1, typeName: "草" }, { id: 2, typeName: "毒" }],
        category: "种子宝可梦",
        description: "背上背着种子的宝可梦。在阳光下晒太阳后，种子会逐渐长大。",
        ability1: "茂盛",
        ability1Description: "HP减少时，草属性招式的威力会提高。",
        hiddenAbility: "叶绿素",
        hiddenAbilityDescription: "晴朗天气时，速度会提高。",
        hp: 45,
        attack: 49,
        defense: 49,
        spAttack: 65,
        spDefense: 65,
        speed: 45,
        evolutionStage: 0,
        hasForms: 0,
        isDefault: 1
      },
      {
        id: 4,
        number: "004",
        pokemonName: "小火龙",
        imageUrl: "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/4.png",
        types: [{ id: 3, typeName: "火" }],
        category: "蜥蜴宝可梦",
        description: "尾巴上燃烧着火焰的宝可梦。火焰的大小表示它的健康状态。",
        ability1: "猛火",
        ability1Description: "HP减少时，火属性招式的威力会提高。",
        hiddenAbility: "太阳之力",
        hiddenAbilityDescription: "晴朗天气时，特攻会提高，但每回合会减少HP。",
        hp: 39,
        attack: 52,
        defense: 43,
        spAttack: 60,
        spDefense: 50,
        speed: 65,
        evolutionStage: 0,
        hasForms: 0,
        isDefault: 1
      },
      {
        id: 6,
        number: "006",
        pokemonName: "喷火龙",
        imageUrl: "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/6.png",
        types: [{ id: 3, typeName: "火" }, { id: 5, typeName: "飞行" }],
        category: "火焰宝可梦",
        description: "喷火龙（日文：リザードン，英文：Charizard）是火属性和飞行属性宝可梦。喷火龙的设计者为田尻智。超级喷火龙X的设计者为杉森建。",
        ability1: "猛火",
        ability1Description: "HP减少时，火属性招式的威力会提高。",
        hiddenAbility: "太阳之力",
        hiddenAbilityDescription: "晴朗天气时，特攻会提高，但每回合会减少HP。",
        hp: 78,
        attack: 84,
        defense: 78,
        spAttack: 109,
        spDefense: 85,
        speed: 100,
        evolutionStage: 2,
        hasForms: 0,
        isDefault: 1
      },
      {
        id: 7,
        number: "007",
        pokemonName: "杰尼龟",
        imageUrl: "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/7.png",
        types: [{ id: 4, typeName: "水" }],
        category: "小龟宝可梦",
        description: "缩进壳里可以防御攻击的宝可梦。受到攻击时会缩进壳中保护自己。",
        ability1: "激流",
        ability1Description: "HP减少时，水属性招式的威力会提高。",
        hiddenAbility: "雨盘",
        hiddenAbilityDescription: "下雨天气时，每回合会回复HP。",
        hp: 44,
        attack: 48,
        defense: 65,
        spAttack: 50,
        spDefense: 64,
        speed: 43,
        evolutionStage: 0,
        hasForms: 0,
        isDefault: 1
      },
      {
        id: 25,
        number: "025",
        pokemonName: "皮卡丘",
        imageUrl: "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/25.png",
        types: [{ id: 6, typeName: "电" }],
        category: "鼠宝可梦",
        description: "它会把电力储存在脸颊的电囊里。受到刺激时，就会放出电击。",
        ability1: "静电",
        ability1Description: "因为身上带有静电，有时会让碰到的对手陷入麻痹状态。",
        hiddenAbility: "避雷针",
        hiddenAbilityDescription: "将电属性的招式吸引到自己身上，不会受到伤害，而是会提高特攻。",
        hp: 35,
        attack: 55,
        defense: 40,
        spAttack: 50,
        spDefense: 50,
        speed: 90,
        evolutionStage: 1,
        hasForms: 0,
        isDefault: 1
      },
      {
        id: 150,
        number: "150",
        pokemonName: "超梦",
        imageUrl: "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/150.png",
        types: [{ id: 7, typeName: "超能力" }],
        category: "基因宝可梦",
        description: "由研究者的手改造梦幻的基因而诞生的宝可梦。心情凶暴。",
        ability1: "精神力",
        ability1Description: "拥有训练有素的精神力，不会陷入畏缩状态。",
        hiddenAbility: "紧张感",
        hiddenAbilityDescription: "给予对手紧张感，使其无法食用树果。",
        hp: 106,
        attack: 110,
        defense: 90,
        spAttack: 154,
        spDefense: 90,
        speed: 130,
        evolutionStage: 0,
        hasForms: 0,
        isDefault: 1
      }
    ],
    msg: "模拟数据加载成功"
  });
}

// ==================== 进化页面专用API ====================

/**
 * 进化页面专用：获取宝可梦列表（支持属性筛选和名称搜索）
 * @param {Object} params 查询参数
 * @param {string} params.query - 搜索关键词（宝可梦名称或编号）
 * @param {string} params.type1 - 第一属性（中文，如：草、火、水）
 * @param {string} params.type2 - 第二属性（中文，如：毒、飞行）
 * @returns {Promise} 宝可梦列表数据
 */
export function getPokemonListForEvolution(params = {}) {
  return service.get("/pokemon/evolution", { params });
}